//
// Created by SDSC\202100300261 on 23-11-13.
//

#ifndef COMPILER_TABLE_H
#define COMPILER_TABLE_H


#include <string>
#include "sym.h"
class TABLE_ENTRY {
public:
    TABLE_ENTRY();
    TABLE_ENTRY(
            std::string _name,SYMS _kind,int _value,int _level,int _adr
    );
    friend std::ostream& operator<<(std::ostream& os,const TABLE_ENTRY& obj);
    friend bool operator == (const TABLE_ENTRY& a,const TABLE_ENTRY& b);
    std::string name;
    SYMS kind;
    int value;
    int level;
    int adr;
};

class TABLE {
public:
    TABLE();
    /**
     * 添加过程和自定义标识符
     */
    void addConst(const std::string& name,int value);
    void addVar(const std::string& name);
    int addPro(const std::string& name);
    void setPro(int index,int adr);
    /**
     * 结束一个过程
     */
    void killPro();
    /**
     * 获取列表项
     */
     TABLE_ENTRY* getEntry(const std::string &name);

    friend std::ostream& operator<<(std::ostream& os,const TABLE& obj);
    void check(const TABLE_ENTRY* entry);

    int TX,LEVEL;
    std::stack<int> DX;
private:
    std::vector<TABLE_ENTRY> table;
};

#endif //COMPILER_TABLE_H
